package 设计模式;

/**
 * 静态代理模式：代理类和被代理类在编译器就被确定好了
 */
public class StaticProxy implements Factor{
    //代理类，,继承Factor接口
    private Factor factor;
    public static void main(String[] args) {
        //实例化被代理类对象
        ClothFactory clothFactory = new ClothFactory();
        //实例化代理类对象
        StaticProxy staticProxy = new StaticProxy(clothFactory);
        staticProxy.produce();
    }
    //构造器
    public StaticProxy(Factor factor) {
        this.factor = factor;
    }
    @Override
    public void produce() {
        System.out.println("干活");
        factor.produce();
        System.out.println("收工");
    }
}
//被代理类,继承Factor接口
class  ClothFactory implements Factor{
    @Override
    public void produce() {
        System.out.println("生产");
    }
}
interface Factor{
    void produce();
}
